;define(function (require) {
	'use strict';
	var $=require('jquery');
	var logs=require('plugin/logs');
	function nav(id,pid){
		this.id=id;
		this.pid=pid
		this.cdom=null;
		this.init();
	}
	nav.prototype={
		init:function(){
			this.x=$(this.id).position().left;
			this.pw=$(this.pid).width();
			this.cdom=$(this.id).find('.active');
		},
		run:function(){
			var that=this;
			that.move2active();
			$(document).on('mouseover',this.id+' .menu',function(){
				var x=$(this).position().left-that.x;
				var w=$(this).outerWidth();
				var left=(x+w/2-that.pw/4)+'px'
				that.move(left);
			});
			$(document).on('mouseout',this.id+' .menu',function(){
				if(this.cdom!=$(this))
					that.move2active();
			});
			$(document).on('click',this.id+' .menu',function(){
				$(that.id).find('.active').removeClass('active');
				$(this).addClass('active');
				that.cdom=$(this);
			});
		},
		move:function(left){
			$(this.pid).css('margin-left',left);
		},
		move2active:function(){
			var x=this.cdom.position().left-this.x;
			var w=this.cdom.outerWidth();
			var left=(x+w/2-this.pw/4)+'px'
			this.move(left);
		}
	}
	return nav;
});